#ifndef DEQUE_HPP
#define DEQUE_HPP

#include "SqQueue.hpp"


class Deque : public SqQueueC {
public:
    Deque() {
        initQueue(q);
    }

    Status deFront(QElemType &e) {
        deQueue(q, e);
        return Status::Ok;
    }

    Status deRear(QElemType &e) {
        if (queueEmpty(q)) {
            return Status::Err;
        }
        q.rear = (q.rear - 1 + QueueMaxSize) % QueueMaxSize;
        e = q.base[q.rear];
        return Status::Ok;
    }

    Status enFront(QElemType e) {
        if ((q.front -1 + QueueMaxSize) %QueueMaxSize == q.rear) {
            return Status::Err;
        }

        q.front = (q.front -1 +QueueMaxSize) %QueueMaxSize;
        q.base[q.front] = e;
        return Status::Ok;
    }

    Status enRear(QElemType e) {
        enQueue(q, e);
        return Status::Ok;
    }

    ~Deque() {
        destoryQueue(q);
    }

private:
    Queue q;
};

#endif
